package com.iceclean.daoImpl;

import com.iceclean.dao.PostLikedDao;
import com.iceclean.po.PostLiked;
import com.iceclean.util.JdbcUtil;

import java.util.List;

/**
 * @author : Ice'Clean
 * @date : 2021-05-05
 *
 * 贴子点赞表操作实现类
 */
public class PostLikedDaoImpl implements PostLikedDao {

    @Override
    public PostLiked findPostLiked(int postId, int userId) {
        List<PostLiked> postLikes = JdbcUtil.query("select * from t_post_liked where post_id = ? and user_id = ?", PostLiked.class, postId, userId);
        return postLikes.size() == 0 ? null : postLikes.get(0);
    }

    @Override
    public PostLiked findPostLikedById(int postLikedId) {
        List<PostLiked> postLikes = JdbcUtil.query("select * from t_post_liked where liked_id = ?", PostLiked.class, postLikedId);
        return postLikes.size() == 0 ? null : postLikes.get(0);
    }

    @Override
    public int createPostLiked(PostLiked postLiked) {
        return JdbcUtil.insert("t_post_liked", postLiked);
    }

    @Override
    public boolean cancelPostLiked(PostLiked postLiked) {
        return JdbcUtil.delete("t_post_liked", "liked_id=" + postLiked.getLikedId());
    }


}
